import {
  Controller,
  DefaultValuePipe,
  Get,
  Param,
  ParseBoolPipe,
  ParseIntPipe,
  Query,
  Res,
  UseGuards, UseInterceptors,
} from '@nestjs/common';
import ValidationPipe from '../pipes/validation.pipe';
import { AuthGuard } from '../auth.guard';
import { LoggingInterceptor } from '../interceptors/logging.interceptor';
import { TransformInterceptor } from '../interceptors/transform.interceptor';
import ExcludeNullInterceptor from '../interceptors/parseNull.interceptor'
import {User} from '../decorators/user2'
const path = require('path');

@UseInterceptors(ExcludeNullInterceptor, LoggingInterceptor, TransformInterceptor)
@Controller('demo2')
export class Demo2Controller {
  @Get('/num/:id')
  get1(@Param('id', ValidationPipe) id: string): string {
    return id;
  }

  @UseGuards(AuthGuard)
  @Get('/num2')
  get2(@Query('a', new DefaultValuePipe(false), ParseBoolPipe) a: boolean, @User('hua', ParseIntPipe) u) {
    console.log(u);
    console.log(a);
    return null;
  }


  @Get("/html")
  html(@Res() res){
    res.sendFile(path.resolve(__dirname, '../../', 'public/demo.html'))
  }
}
